package cn.edu.huanu.servletlearn;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author hb
 * @date 2025-09-28 15:33:12
 */
@WebServlet("*.um")
public class UserManagerAction extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();

        String servletPath = request.getServletPath();
        if("/login.um".equals(servletPath)){
            //获得请求参数
            String username = request.getParameter("username");
            String pwd = request.getParameter("pwd");
            System.out.println(username+":"+pwd);
            if("haoren".equals(username)&&"123456".equals(pwd)){
               // out.println("登录成功");
                //重定向
                response.sendRedirect("index.html");
            }else{
               // out.println("登录失败");
                response.sendRedirect("login2.html");
            }
        }
    }
}
